package com.weilive.core.utils;

import java.security.MessageDigest;

public class MD5Utils {

	public static final String KEY_MD5 = "MD5";

	public static byte[] encrypt(byte[] data) throws Exception {
		MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
		md5.update(data);
		return md5.digest();
	}

	public static String encryptToBase64(String data) throws Exception {
		return Base64Utils.encoder(encrypt(data.getBytes()));
	}

	public final static String encryptToHex(String data) throws Exception {
		return HexStringUtils.encrypt(encrypt(data.getBytes()));
	}

	public static void main(String[] args) throws Exception {
		System.out.println(encryptToBase64("1001"));
		System.out.println(encryptToHex("1001"));
	}
}
